import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

/**
 * 直接登录一下数字化平台
 */
public class Brush_Szh {
    public static void main(String[] args) {

        //指定配置
        System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");

        //隐藏浏览器
//        ChromeOptions chromeOptions = new ChromeOptions();
//        chromeOptions.addArguments("--headless");

        //声明浏览器
        ChromeDriver driver = new ChromeDriver();

        //登录
        driver.get("http://iscsso.sgcc.com.cn/isc_sso/login?service=http://open.sgcc.com.cn/pi6000-ua-web/api/daptValidate?target=http://open.sgcc.com.cn");
        driver.findElement(By.id("department")).click();
        driver.findElement(By.className("tab_item2")).click();
        driver.findElement(By.linkText("河南电力")).click();

        driver.findElement(By.id("username")).sendKeys("liuyong21");
        driver.findElement(By.id("password")).sendKeys("hndl@2020");
        driver.findElement(By.id("submit_login")).click();
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.getPageSource();


        //成果汇聚
        driver.findElement(By.linkText("成果汇聚")).click();
        driver.findElement(By.cssSelector(".search-line:nth-child(2) > div > .tagItem")).click();
        driver.findElement(By.cssSelector(".search-line:nth-child(2) .tagItem:nth-child(15) > span")).click();
        driver.executeScript("window.scrollTo(0,608)");
        driver.findElement(By.cssSelector(".ach-item:nth-child(2) > div > .ach-item-item:nth-child(1)")).click();
        driver.findElement(By.cssSelector(".ach-item:nth-child(2) > div > .ach-item-item:nth-child(1)")).click();
        driver.quit();  // 关闭浏览器
    }

    public static String tableCell(WebDriver driver, int row, int column) {
        String text = null;
        //表头
        row = row + 1;
        String xpath = "//*[@class='mini-grid-table']/tbody/tr[" + row + "]/td[" + column + "]";
        WebElement table = driver.findElement(By.xpath(xpath));
        text = table.getText();
        return text;
    }
}
